import request from '../utils/request.js'

// 上传
export function upload(data) {
	return request({
		url: 'business/bloodPreResults/save',
		method: 'POST',
		data
	})
}

// 创建血压记录
export function createBloodPressureRecord(data) {
	return request({
		url: 'business/bloodPreResults/save',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 上传新的血压测量结果
export function uploadNewResult(data) {
	return request({
		url: 'business/bloodPreResults/uploadNewResult',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 批量上传血压记录
export function batchUploadResults(ids, deviceName = '') {
	return request({
		url: 'business/bloodPreResults/batchUploadResults',
		method: 'POST',
		data: ids,
		headers: {
			'Content-Type': 'application/json'
		}
	})
}

// 查询分页列表
export function queryListPage(data) {
	return request({
		url: 'business/bloodPreResults/queryListPage',
		method: 'POST',
		data
	})
}

// 保存设备信息
export function saveDeviceInfo(data) {
	return request({
		url: 'business/deviceInfo/save',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 查询设备信息列表
export function queryDeviceInfoList(data) {
	return request({
		url: 'business/deviceInfo/queryListPage',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 根据条码号查询用户信息
export function getUserInfoByBarCode(barCode) {
	return request({
		url: `business/bloodPreResults/getBarCode?barCode=${barCode}`,
		method: 'GET'
	})
}

// 获取AI智能上传结果
export function getAiSubmitResult() {
	return request({
		url: 'business/bloodPreResults/getAiSubmitResult',
		method: 'POST',
		data: {},
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// AI智能上传确认
export function aiSubmit() {
	return request({
		url: 'business/bloodPreResults/aiSubmit',
		method: 'POST',
		data: {},
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 批量删除血压记录
export function deleteBatchResults(ids) {
	return request({
		url: 'business/bloodPreResults/delBatch',
		method: 'POST',
		data: ids,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// ==================== 设备管理相关接口 ====================

// 查询设备列表分页
export function queryDeviceListPage(data) {
	return request({
		url: 'business/deviceInfo/queryListPage',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 新增设备
export function addDevice(data) {
	return request({
		url: 'business/deviceInfo/save',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 更新设备
export function updateDevice(data) {
	return request({
		url: 'business/deviceInfo/save',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 批量删除设备
export function deleteDevice(ids) {
	return request({
		url: 'business/deviceInfo/delBatch',
		method: 'POST',
		data: ids,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// ==================== 版本管理相关接口 ====================

// 查询版本列表分页
export function queryVersionListPage(data) {
	return request({
		url: 'sys/version/queryListPage',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 新增版本
export function addVersion(data) {
	return request({
		url: 'sys/version/save',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 更新版本
export function updateVersion(data) {
	return request({
		url: 'sys/version/save',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 批量删除版本
export function deleteVersion(ids) {
	return request({
		url: 'sys/version/delBatch',
		method: 'DELETE',
		data: ids,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 文件上传
export function uploadFile(file) {
	const formData = new FormData()
	formData.append('file', file)

	return request({
		url: 'sys/file/uploadFile',
		method: 'POST',
		data: formData,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	})
}

// 上传应用版本
export function uploadApp(file, version, updateLog) {
	const formData = new FormData()
	formData.append('file', file)
	formData.append('version', version)
	formData.append('updateLog', updateLog)

	return request({
		url: 'sys/version/uploadApp',
		method: 'POST',
		data: formData,
		headers: {
			'Content-Type': 'multipart/form-data'
		}
	})
}

// ==================== 用户管理相关接口 ====================

// 查询用户列表分页
export function queryUserListPage(data) {
	return request({
		url: 'sys/user/queryListPage',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 新增用户
export function addUser(data) {
	return request({
		url: 'sys/user/createUser',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 更新用户
export function updateUser(data) {
	return request({
		url: 'sys/user/updateUser',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 批量删除用户
export function deleteUser(ids) {
	return request({
		url: 'sys/user/deleteBatchUser',
		method: 'POST',
		data: ids,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 重置用户密码
export function resetUserPassword(userId) {
	return request({
		url: 'sys/user/resetPassword',
		method: 'POST',
		data: { id: userId },
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 修改用户密码
export function editUserPassword(data) {
	return request({
		url: 'sys/auth/editPassword',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 导出用户数据
export function exportUserData(params) {
	return request({
		url: 'sys/user/export',
		method: 'GET',
		params: params,
		responseType: 'blob',
		timeout: 60000 // 增加超时时间到60秒
	})
}

// ==================== 上传数据管理相关接口 ====================

// 查询血压上传记录列表分页
export function findBPUploadRecordListPage(data) {
	return request({
		url: 'business/bloodPreResults/findBPUploadRecordListPage',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// ==================== 工作量管理相关接口 ====================

// 统计操作员测量次数
export function countBlNum(data) {
	return request({
		url: 'business/workCountManger/countBlNum',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}

// 统计条码号测量次数
export function countBarCode(data) {
	return request({
		url: 'business/workCountManger/countBarCode',
		method: 'POST',
		data,
		headers: {
			'Content-Type': 'application/json; charset=UTF-8'
		}
	})
}